using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BaseForum.Model;
using WebForum.App_Data;

namespace WebForum
{
    public partial class ChangePass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            User user = (User)Session["user"];
            if (Common.HashMD5(TextBoxOld.Text) == user.Password)
            {
                //user.Password = Common.HashMD5(TextBoxNew.Text);
                if (UserDataSource.ChangePass(user.Id, user.Password, Common.HashMD5(TextBoxNew.Text)))
                {
                    Common.Show("Change password success!", "AllForum.aspx");
                }
            }
            else
            {
                Common.Show("Change password faild!", Request.RawUrl);
            }
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("AllForum.aspx");
        }
    }
}
